# todo
# 在这里实现关于插件注册的命令系统相关的代码
import inspect
from .InfoClasses import CommandNodeInfo
from .PluginList import CommandTree, SavedCommandNodeInfo


class RegisterCommandNode:
    def __init__(self, info: CommandNodeInfo):
        SavedCommandNodeInfo.update({info.mount_point: info})
        self.mount_point = info.mount_point

    def __call__(self, target):
        methods = inspect.getmembers(target, predicate=inspect.ismethod)
        functions = [(name, inspect.signature(method).parameters) for name, method in methods if
                     name.startswith("do_")]
        tree = {f"!!{self.mount_point}": {}}
        for name, param in functions:
            tree[f"!!{self.mount_point}"].update({name: param})
        CommandTree.update(tree)
